﻿<Window x:Class="CodeIDX.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:Commands="clr-namespace:CodeIDX.ViewModels.Commands"
        xmlns:Controls="clr-namespace:CodeIDX.Views.Resources.Controls"
        xmlns:Converters="clr-namespace:CodeIDX.Views.Resources.Converters"
        xmlns:Settings="clr-namespace:CodeIDX.Settings"
        xmlns:System="clr-namespace:System;assembly=mscorlib"
        xmlns:ViewModels="clr-namespace:CodeIDX.ViewModels"
        xmlns:avalonEdit="http://icsharpcode.net/sharpdevelop/avalonedit"
        xmlns:local="clr-namespace:CodeIDX"
        xmlns:scm="clr-namespace:System.ComponentModel;assembly=WindowsBase"
        xmlns:searchServices="clr-namespace:CodeIDX.Services.Lucene"
        xmlns:toolkit="http://schemas.xceed.com/wpf/xaml/toolkit"
        xmlns:xcdg="http://schemas.xceed.com/wpf/xaml/datagrid"
        xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
        Width="800"
        Height="600"
        MinWidth="400"
        MinHeight="400"
        PreviewMouseUp="Window_PreviewMouseUp">
    <Window.Style>
        <Style BasedOn="{StaticResource {x:Type Window}}"
               TargetType="{x:Type Window}">
            <Setter Property="Title" Value="CodeIDX" />

            <Style.Triggers>
                <DataTrigger Binding="{Binding DataContext.CurrentIndexFile,
                                               RelativeSource={RelativeSource Self},
                                               Converter={x:Static Converters:IsNullToBoolReversedConverter.Instance}}"
                             Value="True">
                    <Setter Property="Title" Value="{Binding DataContext.CurrentIndexFile.Name, RelativeSource={RelativeSource Self}, StringFormat={}CodeIDX - {0}}" />
                </DataTrigger>
            </Style.Triggers>
        </Style>
    </Window.Style>

    <Window.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="Views/Resources/MainWindowResources.xaml" />
            </ResourceDictionary.MergedDictionaries>

            <ContextMenu x:Key="SearchTabContextMenu">
                <MenuItem Click="SearchTab_Close_Click"
                          Header="Close" />
                <MenuItem Click="SearchTab_Close_All"
                          Header="Close All" />
                <MenuItem Click="SearchTab_CloseAllButThis_Click"
                          Header="Close All But This" />
                <MenuItem Click="SearchTab_CloseLeft_Click"
                          Header="Close Left" />
                <MenuItem Click="SearchTab_CloseRight_Click"
                          Header="Close Right" />
            </ContextMenu>

        </ResourceDictionary>
    </Window.Resources>

    <Grid x:Name="rootGrid">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>

        <Menu>
            <MenuItem Header="File">
                <MenuItem Command="Commands:ApplicationViewCommands.CreateIndexCommand"
                          CommandParameter="{Binding DataContext,
                                                     RelativeSource={RelativeSource Self}}"
                          Header="New"
                          IsEnabled="{Binding IsReady}">
                    <MenuItem.Icon>
                        <Image Width="16"
                               Height="16"
                               Source="pack://application:,,,/CodeIDX;component/Views/Resources/Images/createIndex.png" />
                    </MenuItem.Icon>
                </MenuItem>
                <MenuItem Click="OpenIndex_Click"
                          Header="Open"
                          IsEnabled="{Binding IsReady}">
                    <MenuItem.Icon>
                        <Image Width="16"
                               Height="16"
                               Source="pack://application:,,,/CodeIDX;component/Views/Resources/Images/openIndex.png" />
                    </MenuItem.Icon>
                </MenuItem>
                <MenuItem Header="Recent Indices"
                          ItemsSource="{Binding UserSettings.RecentIndices}">
                    <MenuItem.Style>
                        <Style BasedOn="{StaticResource {x:Type MenuItem}}"
                               TargetType="{x:Type MenuItem}">
                            <Setter Property="IsEnabled" Value="{Binding IsReady}" />
                            <Style.Triggers>
                                <DataTrigger Binding="{Binding Items.Count,
                                                               RelativeSource={RelativeSource Self}}"
                                             Value="0">
                                    <Setter Property="IsEnabled" Value="False" />
                                </DataTrigger>
                            </Style.Triggers>
                        </Style>
                    </MenuItem.Style>
                    <MenuItem.Resources>
                        <Style TargetType="{x:Type MenuItem}">
                            <Setter Property="Header" Value="{Binding Name}" />
                            <Setter Property="ToolTip" Value="{Binding IndexFile}" />
                            <EventSetter Event="Click"
                                         Handler="LoadRecentIndex_Click" />
                        </Style>
                    </MenuItem.Resources>
                </MenuItem>
                <MenuItem Click="Exit_Click"
                          Header="Exit" />
            </MenuItem>

            <MenuItem Header="Index">
                <MenuItem Click="EditIndex_Click"
                          Header="Edit">
                    <MenuItem.IsEnabled>
                        <MultiBinding Converter="{x:Static Converters:ManyBoolsToBoolConverter.Instance}">
                            <Binding Converter="{x:Static Converters:IsNullToBoolReversedConverter.Instance}"
                                     Path="CurrentIndexFile" />
                            <Binding Path="IsReady" />
                        </MultiBinding>
                    </MenuItem.IsEnabled>
                    <MenuItem.Icon>
                        <Image Width="16"
                               Height="16"
                               Source="pack://application:,,,/CodeIDX;component/Views/Resources/Images/editIndex.png" />
                    </MenuItem.Icon>
                </MenuItem>
                <MenuItem Click="UpdateIndex_Click"
                          Header="Refresh"
                          ToolTip="Refresh all indexed files">
                    <MenuItem.IsEnabled>
                        <MultiBinding Converter="{x:Static Converters:ManyBoolsToBoolConverter.Instance}">
                            <Binding Converter="{x:Static Converters:IsNullToBoolReversedConverter.Instance}"
                                     Path="CurrentIndexFile" />
                            <Binding Path="IsReady" />
                        </MultiBinding>
                    </MenuItem.IsEnabled>
                    <MenuItem.Icon>
                        <Image Width="16"
                               Height="16"
                               Source="pack://application:,,,/CodeIDX;component/Views/Resources/Images/refresh.png" />
                    </MenuItem.Icon>
                </MenuItem>
                <MenuItem Header="Auto Update"
                          IsCheckable="True"
                          IsChecked="{Binding AutoUpdateIndex}"
                          ToolTip="Automatically update changed files">
                    <MenuItem.Icon>
                        <Image Width="16"
                               Height="16"
                               Source="pack://application:,,,/CodeIDX;component/Views/Resources/Images/autoRefresh.png" />
                    </MenuItem.Icon>
                </MenuItem>
            </MenuItem>

            <MenuItem Header="Search">
                <MenuItem Command="local:MainWindow.NewSearchCommand"
                          Header="New Search" />
                <MenuItem Click="CloseSearch_Click"
                          Header="Close Search" />
            </MenuItem>

            <MenuItem Header="Tools">
                <MenuItem Header="Enable Editing"
                          IsCheckable="True"
                          IsChecked="{Binding UserSettings.IsEditEnabled}" />
                <MenuItem Header="Enable Blacklist"
                          IsCheckable="True"
                          IsChecked="{Binding UserSettings.IsBlacklistEnabled}" />
                <Separator />
                <MenuItem Command="local:MainWindow.ExportResultsCommand"
                          Header="Export Results …" />
                <Separator />
                <MenuItem Click="ShowOptions_Click"
                          Header="Options …" />
            </MenuItem>

            <MenuItem Header="View">
                <MenuItem Command="local:MainWindow.TogglePreviewCommand"
                          Header="Preview"
                          IsCheckable="True"
                          IsChecked="{Binding UserSettings.IsPreviewVisible,
                                              Mode=OneWay}" />
            </MenuItem>

            <MenuItem Header="Help">
                <MenuItem Click="OpenChangelog_Click"
                          Header="Changes" />
                <MenuItem Click="OpenReadme_Click"
                          Header="Readme" />
                <Separator />
                <MenuItem Click="About_Click"
                          Header="About CodeIDX …">
                    <!--
                        <MenuItem.Icon>
                        <Image Width="16"
                        Height="16"
                        Source="pack://application:,,,/CodeIDX;component/Views/Resources/Images/info.png" />
                        </MenuItem.Icon>
                    -->
                </MenuItem>
            </MenuItem>
        </Menu>

        <!--  Main Grid  -->
        <Grid x:Name="MainGrid"
              Grid.Row="1">
            <Grid.RowDefinitions>
                <RowDefinition Height="*"
                               MinHeight="100" />
                <RowDefinition Height="Auto" />
                <RowDefinition x:Name="PreviewGridRow"
                               Height="0" />
            </Grid.RowDefinitions>

            <TabControl x:Name="tcMain"
                        ItemsSource="{Binding Searches}"
                        MouseDown="SearchResults_MouseDown"
                        SelectedItem="{Binding CurrentSearch}"
                        SelectionChanged="SearchTab_SelectionChanged">

                <TabControl.ItemContainerStyle>
                    <Style TargetType="{x:Type TabItem}">
                        <Setter Property="MaxWidth" Value="200" />
                        <Setter Property="ToolTip" Value="{Binding LastSearchText}" />
                        <Setter Property="ContextMenu" Value="{StaticResource SearchTabContextMenu}" />
                        <Setter Property="HeaderTemplate">
                            <Setter.Value>
                                <DataTemplate>
                                    <TextBlock Text="&lt;empty&gt;" />
                                </DataTemplate>
                            </Setter.Value>
                        </Setter>

                        <Style.Triggers>
                            <DataTrigger Binding="{Binding SearchText,
                                                           Converter={x:Static Converters:StringNullOrEmptyToBoolReversedConverter.Instance}}"
                                         Value="True">
                                <Setter Property="HeaderTemplate">
                                    <Setter.Value>
                                        <DataTemplate>
                                            <TextBlock Text="{Binding SearchText, StringFormat={}({0})}" />
                                        </DataTemplate>
                                    </Setter.Value>
                                </Setter>
                            </DataTrigger>

                            <DataTrigger Binding="{Binding LastSearchText,
                                                           Converter={x:Static Converters:StringNullOrEmptyToBoolReversedConverter.Instance}}"
                                         Value="True">
                                <Setter Property="HeaderTemplate">
                                    <Setter.Value>
                                        <DataTemplate>
                                            <StackPanel Orientation="Horizontal">
                                                <TextBlock Text="*"
                                                           Visibility="{Binding HasLazyResults,
                                                                                Converter={x:Static Converters:BoolToVisibilityConverter.Instance}}" />
                                                <TextBlock>
                                                    <TextBlock.Text>
                                                        <MultiBinding StringFormat="{}({1}) {0}">
                                                            <Binding Path="LastSearchText" />
                                                            <Binding FallbackValue="0"
                                                                     Path="SearchResultsView.View.Count" />
                                                        </MultiBinding>
                                                    </TextBlock.Text>
                                                </TextBlock>
                                            </StackPanel>
                                        </DataTemplate>
                                    </Setter.Value>
                                </Setter>
                            </DataTrigger>

                            <MultiDataTrigger>
                                <MultiDataTrigger.Conditions>
                                    <Condition Binding="{Binding LastSearchText, Converter={x:Static Converters:StringNullOrEmptyToBoolReversedConverter.Instance}}" Value="True" />
                                    <Condition Binding="{Binding Path=ShowResultFileCount, Source={x:Static Settings:CodeIDXSettings.UserInterface}}" Value="True" />
                                </MultiDataTrigger.Conditions>

                                <Setter Property="HeaderTemplate">
                                    <Setter.Value>
                                        <DataTemplate>
                                            <StackPanel Orientation="Horizontal">
                                                <TextBlock Text="*"
                                                           Visibility="{Binding HasLazyResults,
                                                                                Converter={x:Static Converters:BoolToVisibilityConverter.Instance}}" />
                                                <TextBlock>
                                                    <TextBlock.Text>
                                                        <MultiBinding StringFormat="{}({1} : {2}) {0}">
                                                            <Binding Path="LastSearchText" />
                                                            <Binding FallbackValue="0"
                                                                     Path="SearchResultsView.View.Count" />
                                                            <Binding FallbackValue="0"
                                                                     Path="FileCount" />
                                                        </MultiBinding>
                                                    </TextBlock.Text>
                                                </TextBlock>
                                            </StackPanel>
                                        </DataTemplate>
                                    </Setter.Value>
                                </Setter>
                            </MultiDataTrigger>
                        </Style.Triggers>
                    </Style>
                </TabControl.ItemContainerStyle>

                <TabControl.ContentTemplate>
                    <DataTemplate>
                        <Grid>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto" />
                                <RowDefinition Height="*" />
                            </Grid.RowDefinitions>

                            <Grid Grid.Row="0">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="*" />
                                    <ColumnDefinition Width="Auto" />
                                    <ColumnDefinition Width="Auto" />
                                    <ColumnDefinition Width="Auto" />
                                    <ColumnDefinition Width="Auto" />
                                    <ColumnDefinition Width="Auto" />
                                    <ColumnDefinition Width="3" />
                                    <ColumnDefinition Width="Auto" />
                                </Grid.ColumnDefinitions>

                                <TextBox Grid.Column="0"
                                         Margin="0,2,3,2"
                                         PreviewKeyDown="Search_KeyDown"
                                         Text="{Binding SearchText,
                                                        UpdateSourceTrigger=PropertyChanged}"
                                         Visibility="{Binding EnableSearchHistory,
                                                              Source={x:Static Settings:CodeIDXSettings.Search},
                                                              Converter={x:Static Converters:BoolToVisibilityReversedConverter.Instance}}"
                                         local:MainWindow.IsSearchTextBox="True" />

                                <ComboBox Grid.Column="0"
                                          Margin="0,2,3,2"
                                          IsEditable="True"
                                          IsTextSearchEnabled="False"
                                          ItemsSource="{Binding DataContext.SearchHistory,
                                                                RelativeSource={RelativeSource Mode=FindAncestor,
                                                                                               AncestorType={x:Type TabControl}}}"
                                          PreviewKeyDown="Search_KeyDown"
                                          Text="{Binding SearchText,
                                                         UpdateSourceTrigger=PropertyChanged}"
                                          Visibility="{Binding EnableSearchHistory,
                                                               Source={x:Static Settings:CodeIDXSettings.Search},
                                                               Converter={x:Static Converters:BoolToVisibilityConverter.Instance}}"
                                          local:MainWindow.IsSearchTextBox="True" />

                                <Button Grid.Column="1"
                                        Command="Commands:SearchViewCommands.RunSearchCommand"
                                        CommandParameter="{Binding DataContext,
                                                                   RelativeSource={RelativeSource Self}}"
                                        ToolTip="Run search">
                                    <Button.Content>
                                        <Image Width="16"
                                               Height="16"
                                               Source="pack://application:,,,/CodeIDX;component/Views/Resources/Images/search.png" />
                                    </Button.Content>
                                </Button>

                                <ToggleButton Grid.Column="2"
                                              Margin="3,2,5,2"
                                              IsChecked="{Binding IsSearchingInResults}"
                                              ToolTip="Fix search result files">
                                    <ToggleButton.Style>
                                        <Style BasedOn="{StaticResource {x:Type ToggleButton}}"
                                               TargetType="ToggleButton">
                                            <Setter Property="Content">
                                                <Setter.Value>
                                                    <Image Width="16"
                                                           Height="16"
                                                           Source="pack://application:,,,/CodeIDX;component/Views/Resources/Images/unlocked.png" />
                                                </Setter.Value>
                                            </Setter>
                                            <Style.Triggers>
                                                <DataTrigger Binding="{Binding LastSearchText,
                                                                               Converter={x:Static Converters:StringNullOrEmptyToBoolConverter.Instance}}"
                                                             Value="True">
                                                    <Setter Property="Visibility" Value="Collapsed" />
                                                </DataTrigger>
                                                <DataTrigger Binding="{Binding EnableSearchInResults,
                                                                               Source={x:Static Settings:CodeIDXSettings.Search}}"
                                                             Value="False">
                                                    <Setter Property="Visibility" Value="Collapsed" />
                                                </DataTrigger>
                                                <Trigger Property="IsChecked" Value="True">
                                                    <Setter Property="Content">
                                                        <Setter.Value>
                                                            <Image Width="16"
                                                                   Height="16"
                                                                   Source="pack://application:,,,/CodeIDX;component/Views/Resources/Images/locked.png" />
                                                        </Setter.Value>
                                                    </Setter>
                                                </Trigger>
                                            </Style.Triggers>
                                        </Style>
                                    </ToggleButton.Style>
                                </ToggleButton>

                                <ToggleButton Grid.Column="3"
                                              IsChecked="{Binding MatchCase,
                                                                  UpdateSourceTrigger=PropertyChanged}"
                                              ToolTip="Match case">
                                    <ToggleButton.Content>
                                        <Image Width="16"
                                               Height="16"
                                               Source="pack://application:,,,/CodeIDX;component/Views/Resources/Images/matchCase.png" />
                                    </ToggleButton.Content>
                                </ToggleButton>

                                <ToggleButton Grid.Column="4"
                                              IsChecked="{Binding MatchWholeWord,
                                                                  UpdateSourceTrigger=PropertyChanged}"
                                              ToolTip="Match whole word">
                                    <ToggleButton.Content>
                                        <Image Width="16"
                                               Height="16"
                                               Source="pack://application:,,,/CodeIDX;component/Views/Resources/Images/matchWholeWord.png" />
                                    </ToggleButton.Content>
                                </ToggleButton>

                                <ToggleButton Grid.Column="5"
                                              IsChecked="{Binding EnableWildcards,
                                                                  UpdateSourceTrigger=PropertyChanged}"
                                              ToolTip="Use Wildcards">
                                    <ToggleButton.Content>
                                        <Image Width="16"
                                               Height="16"
                                               Source="pack://application:,,,/CodeIDX;component/Views/Resources/Images/wildcard.png" />
                                    </ToggleButton.Content>
                                </ToggleButton>


                                <!--  Filter  -->
                                <Grid Grid.Column="7"
                                      Margin="3,0,0,0">
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="*" />
                                        <ColumnDefinition Width="Auto" />
                                    </Grid.ColumnDefinitions>

                                    <Grid Visibility="{Binding IsFilterEnabled, Converter={x:Static Converters:BoolToVisibilityConverter.Instance}}">
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="Auto" />
                                            <ColumnDefinition Width="Auto" />
                                            <ColumnDefinition Width="Auto" />
                                        </Grid.ColumnDefinitions>

                                        <!--  Directory Filter  -->
                                        <xctk:WatermarkTextBox Width="150"
                                                               Margin="3,2"
                                                               Text="{Binding DirectoryFilterExpression,
                                                                              UpdateSourceTrigger=PropertyChanged}"
                                                               Visibility="{Binding Path=EnableDirectoryFilter,
                                                                                    Source={x:Static Settings:CodeIDXSettings.Search},
                                                                                    Converter={x:Static Converters:BoolToVisibilityConverter.Instance}}"
                                                               Watermark="Directory Filter" />

                                        <!--  File Filter  -->
                                        <xctk:WatermarkTextBox Grid.Column="1"
                                                               Width="150"
                                                               Margin="3,2"
                                                               Text="{Binding FileFilterExpression,
                                                                              UpdateSourceTrigger=PropertyChanged}"
                                                               Visibility="{Binding Path=EnableFileFilter,
                                                                                    Source={x:Static Settings:CodeIDXSettings.Search},
                                                                                    Converter={x:Static Converters:BoolToVisibilityConverter.Instance}}"
                                                               Watermark="File Filter" />

                                        <!--  Extension Filter  -->
                                        <xctk:CheckComboBox Grid.Column="2"
                                                            Width="150"
                                                            Margin="3,2"
                                                            Command="local:MainWindow.ToggleFiletypeFilterCommand"
                                                            Delimiter="; "
                                                            IsEnabled="{Binding Items.Count,
                                                                                RelativeSource={RelativeSource Self},
                                                                                Converter={x:Static Converters:IsLargerThanXToBoolConverter.Instance},
                                                                                ConverterParameter=0}"
                                                            ItemsSource="{Binding AvailableFileFilters}"
                                                            SelectedItemsOverride="{Binding ActiveFileFilters}">
                                            <xctk:CheckComboBox.ItemContainerStyle>
                                                <Style TargetType="{x:Type xctk:SelectorItem}">
                                                    <Setter Property="ToolTip" Value="CTRL to select single item&#10;CTRL + SHIFT to select all other items" />
                                                </Style>
                                            </xctk:CheckComboBox.ItemContainerStyle>
                                        </xctk:CheckComboBox>
                                    </Grid>

                                    <ToggleButton Grid.Column="2"
                                                  Margin="3,2,0,2"
                                                  IsChecked="{Binding IsFilterEnabled}"
                                                  ToolTip="Toggle Filter">
                                        <ToggleButton.Content>
                                            <Image Width="16"
                                                   Height="16"
                                                   Source="pack://application:,,,/CodeIDX;component/Views/Resources/Images/filter.png" />
                                        </ToggleButton.Content>
                                    </ToggleButton>
                                </Grid>
                            </Grid>


                            <ListView x:Name="lvSearchResults"
                                      Grid.Row="1"
                                      DataContextChanged="lvSearchResults_DataContextChanged"
                                      IsSynchronizedWithCurrentItem="True"
                                      ItemsSource="{Binding SearchResultsView.View}"
                                      Loaded="SearchResultsView_Loaded"
                                      MouseMove="SearchResults_MouseMove"
                                      PreviewKeyDown="Result_KeyDown"
                                      PreviewMouseLeftButtonDown="SearchResults_LeftButtonDown"
                                      ScrollViewer.ScrollChanged="SearchResults_ScrollChanged"
                                      SelectedItem="{Binding SelectedResult,
                                                             Mode=OneWay}"
                                      SelectionChanged="SearchResult_SelectionChanged"
                                      VirtualizingPanel.IsVirtualizing="True">
                                <ListView.Resources>
                                    <Style TargetType="{x:Type ListViewItem}">
                                        <Setter Property="HorizontalContentAlignment" Value="Stretch" />
                                        <EventSetter Event="MouseDoubleClick"
                                                     Handler="SearchResult_DoubleClick" />
                                        <Setter Property="ContextMenu">
                                            <Setter.Value>
                                                <ContextMenu>
                                                    <MenuItem Command="Commands:SearchResultViewCommands.OpenLocationCommand"
                                                              CommandParameter="{Binding DataContext,
                                                                                         RelativeSource={RelativeSource Self}}"
                                                              Header="Open Folder" />
                                                    <MenuItem Command="Commands:SearchResultViewCommands.OpenFileCommand"
                                                              CommandParameter="{Binding DataContext,
                                                                                         RelativeSource={RelativeSource Self}}"
                                                              Header="Open File" />
                                                    <MenuItem Command="Commands:SearchResultViewCommands.OpenFileInNotepadCommand"
                                                              CommandParameter="{Binding DataContext,
                                                                                         RelativeSource={RelativeSource Self}}"
                                                              Header="Open File in Notepad"
                                                              ToolTip="Opening file in Notepad++ if installed." />
                                                    <MenuItem Command="Commands:SearchResultViewCommands.CopyFilepathCommand"
                                                              CommandParameter="{Binding DataContext,
                                                                                         RelativeSource={RelativeSource Self}}"
                                                              Header="Copy Full Path" />
                                                    <MenuItem Command="Commands:SearchResultViewCommands.RemoveFileFromResultsCommand"
                                                              CommandParameter="{Binding DataContext,
                                                                                         RelativeSource={RelativeSource Self}}"
                                                              Header="Remove File" />
                                                    <MenuItem Command="Commands:SearchResultViewCommands.FilterFileCommand"
                                                              CommandParameter="{Binding DataContext,
                                                                                         RelativeSource={RelativeSource Self}}"
                                                              Header="Filter File" />
                                                </ContextMenu>
                                            </Setter.Value>
                                        </Setter>
                                    </Style>
                                </ListView.Resources>

                                <ListView.View>
                                    <GridView>
                                        <GridViewColumn Width="300"
                                                        Header="Directory">
                                            <GridViewColumn.CellTemplate>
                                                <DataTemplate>
                                                    <TextBlock HorizontalAlignment="Right"
                                                               Text="{Binding Directory}">
                                                        <TextBlock.Style>
                                                            <Style BasedOn="{StaticResource {x:Type TextBlock}}"
                                                                   TargetType="{x:Type TextBlock}">
                                                                <Setter Property="ToolTip">
                                                                    <Setter.Value>
                                                                        <MultiBinding Converter="{x:Static Converters:CombineStringsConverter.Instance}">
                                                                            <Binding Path="Directory" />
                                                                            <Binding Source="\" />
                                                                            <Binding Path="Filename" />
                                                                            <Binding Path="Extension" />
                                                                        </MultiBinding>
                                                                    </Setter.Value>
                                                                </Setter>
                                                                <Style.Triggers>
                                                                    <DataTrigger Binding="{Binding IsFirstOfFile}"
                                                                                 Value="False">
                                                                        <Setter Property="Foreground" Value="Gray" />
                                                                    </DataTrigger>
                                                                </Style.Triggers>
                                                            </Style>
                                                        </TextBlock.Style>
                                                    </TextBlock>
                                                </DataTemplate>
                                            </GridViewColumn.CellTemplate>
                                        </GridViewColumn>
                                        <GridViewColumn Width="200"
                                                        Header="Filename">
                                            <GridViewColumn.CellTemplate>
                                                <DataTemplate>
                                                    <TextBlock Text="{Binding Filename}">
                                                        <TextBlock.Style>
                                                            <Style BasedOn="{StaticResource {x:Type TextBlock}}"
                                                                   TargetType="{x:Type TextBlock}">
                                                                <Setter Property="ToolTip">
                                                                    <Setter.Value>
                                                                        <MultiBinding Converter="{x:Static Converters:CombineStringsConverter.Instance}">
                                                                            <Binding Path="Directory" />
                                                                            <Binding Source="\" />
                                                                            <Binding Path="Filename" />
                                                                            <Binding Path="Extension" />
                                                                        </MultiBinding>
                                                                    </Setter.Value>
                                                                </Setter>
                                                                <Style.Triggers>
                                                                    <DataTrigger Binding="{Binding IsFirstOfFile}"
                                                                                 Value="False">
                                                                        <Setter Property="Foreground" Value="Gray" />
                                                                    </DataTrigger>
                                                                </Style.Triggers>
                                                            </Style>
                                                        </TextBlock.Style>
                                                    </TextBlock>
                                                </DataTemplate>
                                            </GridViewColumn.CellTemplate>
                                        </GridViewColumn>
                                        <GridViewColumn Width="50"
                                                        DisplayMemberBinding="{Binding Extension}"
                                                        Header="Ext" />
                                        <GridViewColumn Width="50"
                                                        DisplayMemberBinding="{Binding LineNumber}"
                                                        Header="Line" />
                                        <GridViewColumn Header="Match">
                                            <GridViewColumn.CellTemplate>
                                                <DataTemplate>
                                                    <TextBlock Controls:TextBlockEx.FormattedText="{Binding Converter={x:Static Converters:HighlightedSearchResultToInlineConverter.Instance}}" />
                                                </DataTemplate>
                                            </GridViewColumn.CellTemplate>
                                        </GridViewColumn>
                                    </GridView>
                                </ListView.View>
                            </ListView>

                            <!--  Load lazy results buttons  -->
                            <StackPanel Grid.Row="1"
                                        Margin="0,0,25,25"
                                        HorizontalAlignment="Right"
                                        VerticalAlignment="Bottom"
                                        Orientation="Horizontal"
                                        Visibility="{Binding HasLazyResults,
                                                             Converter={x:Static Converters:BoolToVisibilityConverter.Instance}}">
                                <Button Margin="0,0,5,0"
                                        Background="WhiteSmoke"
                                        BorderBrush="#7FACCC"
                                        Command="Commands:SearchViewCommands.LoadAllLazyResultsCommand"
                                        CommandParameter="{Binding Path=.}"
                                        Content="Load All">
                                    <Button.ToolTip>
                                        <ToolTip Content="{Binding LazyResultsCount}"
                                                 ContentStringFormat="{}Load remaining {0} results" />
                                    </Button.ToolTip>
                                </Button>
                                <Button Background="WhiteSmoke"
                                        BorderBrush="#7FACCC"
                                        Command="Commands:SearchViewCommands.LoadNextLazyResultsCommand"
                                        CommandParameter="{Binding Path=.}"
                                        Content="Load Next" />
                            </StackPanel>
                        </Grid>
                    </DataTemplate>
                </TabControl.ContentTemplate>
            </TabControl>

            <GridSplitter x:Name="PreviewSplitter"
                          Grid.Row="1"
                          Height="5"
                          Margin="0,2,0,0"
                          HorizontalAlignment="Stretch"
                          DragCompleted="PreviewSplitter_DragCompleted"
                          MouseDoubleClick="PreviewSplitter_MouseDoubleClick"
                          ResizeBehavior="PreviousAndNext"
                          ResizeDirection="Rows"
                          Style="{StaticResource GridSplitterHorizontalGripStyle}" />

            <Controls:EditableAvalonEditor x:Name="PreviewEditor"
                                           Grid.Row="2"
                                           DataContext="{Binding CurrentSearch.SelectedResult}"
                                           IsEditEnabled="{Binding DataContext.UserSettings.IsEditEnabled,
                                                                   ElementName=MainGrid}" />
        </Grid>

        <StatusBar x:Name="sbStatus"
                   Grid.Row="2"
                   Height="28"
                   VerticalContentAlignment="Center">
            <StatusBar.Style>
                <Style TargetType="{x:Type StatusBar}">
                    <Setter Property="Background" Value="#F1EDED" />
                    <Style.Triggers>
                        <DataTrigger Binding="{Binding IsReady}"
                                     Value="False">
                            <Setter Property="Background" Value="#007ACC" />
                            <Setter Property="Foreground" Value="White" />
                        </DataTrigger>
                        <DataTrigger Binding="{Binding IsUpdating}"
                                     Value="True">
                            <Setter Property="Background" Value="#7FACCC" />
                        </DataTrigger>
                        <DataTrigger Binding="{Binding IsAutomaticUpdateInProgress}"
                                     Value="True">
                            <Setter Property="Background" Value="#BEC6CC" />
                        </DataTrigger>

                        <DataTrigger Binding="{Binding StatusChangeAttempted}"
                                     Value="True">
                            <DataTrigger.EnterActions>
                                <BeginStoryboard>
                                    <Storyboard Duration="0:0:0.6">
                                        <ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(StatusBar.Background).(SolidColorBrush.Color)">
                                            <ColorAnimationUsingKeyFrames.KeyFrames>
                                                <DiscreteColorKeyFrame KeyTime="0:0:0"
                                                                       Value="#F1EDED" />
                                                <DiscreteColorKeyFrame KeyTime="0:0:0.2"
                                                                       Value="#007ACC" />
                                                <DiscreteColorKeyFrame KeyTime="0:0:0.4"
                                                                       Value="#F1EDED" />
                                                <DiscreteColorKeyFrame KeyTime="0:0:0.6"
                                                                       Value="#007ACC" />
                                            </ColorAnimationUsingKeyFrames.KeyFrames>
                                        </ColorAnimationUsingKeyFrames>
                                    </Storyboard>
                                </BeginStoryboard>
                            </DataTrigger.EnterActions>
                        </DataTrigger>

                        <DataTrigger Binding="{Binding OperationCancelled}"
                                     Value="True">
                            <DataTrigger.EnterActions>
                                <BeginStoryboard>
                                    <Storyboard Duration="0:0:1">
                                        <ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(StatusBar.Background).(SolidColorBrush.Color)">
                                            <ColorAnimationUsingKeyFrames.KeyFrames>
                                                <DiscreteColorKeyFrame KeyTime="0:0:0"
                                                                       Value="#C90000" />
                                                <DiscreteColorKeyFrame KeyTime="0:0:1"
                                                                       Value="#F1EDED" />
                                            </ColorAnimationUsingKeyFrames.KeyFrames>
                                        </ColorAnimationUsingKeyFrames>
                                    </Storyboard>
                                </BeginStoryboard>
                            </DataTrigger.EnterActions>
                        </DataTrigger>
                    </Style.Triggers>
                </Style>
            </StatusBar.Style>

            <StatusBarItem Margin="5,0,0,0">
                <TextBlock>
                    <TextBlock.Style>
                        <Style TargetType="{x:Type TextBlock}">
                            <Setter Property="Text" Value="{Binding Status}" />
                            <Style.Triggers>
                                <DataTrigger Binding="{Binding IsReady}"
                                             Value="False">
                                    <Setter Property="Text" Value="{Binding Status, StringFormat='{}{0} …'}" />
                                </DataTrigger>
                                <DataTrigger Binding="{Binding CanCurrentOperationCancel}"
                                             Value="True">
                                    <Setter Property="Text" Value="{Binding Status, StringFormat='{}{0} …    ESC to Cancel'}" />
                                </DataTrigger>
                            </Style.Triggers>
                        </Style>
                    </TextBlock.Style>
                </TextBlock>
            </StatusBarItem>

            <StatusBarItem HorizontalAlignment="Right">
                <StackPanel Orientation="Horizontal">
                    <StatusBarItem Width="20"
                                   Margin="0,0,10,0"
                                   HorizontalContentAlignment="Stretch"
                                   ToolTip="Editing enabled">
                        <StatusBarItem.Style>
                            <Style TargetType="StatusBarItem">
                                <Style.Triggers>
                                    <DataTrigger Binding="{Binding UserSettings.IsEditEnabled}"
                                                 Value="False">
                                        <Setter Property="Visibility" Value="Hidden" />
                                    </DataTrigger>
                                </Style.Triggers>
                            </Style>
                        </StatusBarItem.Style>

                        <TextBlock HorizontalAlignment="Center"
                                   FontWeight="SemiBold"
                                   Text="E" />
                    </StatusBarItem>

                    <StatusBarItem Width="20"
                                   Margin="0,0,10,0"
                                   HorizontalContentAlignment="Stretch"
                                   ToolTip="Filter enabled">
                        <StatusBarItem.Style>
                            <Style TargetType="StatusBarItem">
                                <Style.Triggers>
                                    <DataTrigger Binding="{Binding CurrentSearch.IsFilterEnabled}"
                                                 Value="False">
                                        <Setter Property="Visibility" Value="Hidden" />
                                    </DataTrigger>
                                </Style.Triggers>
                            </Style>
                        </StatusBarItem.Style>

                        <TextBlock HorizontalAlignment="Center"
                                   FontWeight="SemiBold"
                                   Text="F" />
                    </StatusBarItem>

                    <StatusBarItem Width="20"
                                   Margin="0,0,20,0"
                                   HorizontalContentAlignment="Stretch"
                                   ToolTip="Blacklist enabled">
                        <StatusBarItem.Style>
                            <Style TargetType="StatusBarItem">
                                <Style.Triggers>
                                    <DataTrigger Binding="{Binding UserSettings.IsBlacklistEnabled}"
                                                 Value="False">
                                        <Setter Property="Visibility" Value="Hidden" />
                                    </DataTrigger>
                                </Style.Triggers>
                            </Style>
                        </StatusBarItem.Style>

                        <TextBlock HorizontalAlignment="Center"
                                   FontWeight="SemiBold"
                                   Text="B" />
                    </StatusBarItem>

                    <StatusBarItem Margin="0,0,5,0">
                        <!--  <TextBlock Text="{Binding CurrentIndexFile.LastFullRefresh, StringFormat='{}Last refresh: {0:dd.MM.yyyy}'}" />  -->
                        <TextBlock>
                            <TextBlock.Style>
                                <Style TargetType="{x:Type TextBlock}">
                                    <Setter Property="Text" Value="{Binding CurrentIndexFile.LastFullRefresh, StringFormat='{}Last refresh: {0:dd.MM.yyyy}'}" />
                                    <Style.Triggers>
                                        <DataTrigger Binding="{Binding CurrentIndexFile.LastFullRefresh,
                                                                       Converter={x:Static Converters:IsTodayConverter.Instance}}"
                                                     Value="True">
                                            <Setter Property="Text" Value="Last refresh: Today" />
                                        </DataTrigger>
                                    </Style.Triggers>
                                </Style>
                            </TextBlock.Style>
                        </TextBlock>
                    </StatusBarItem>
                </StackPanel>
            </StatusBarItem>
        </StatusBar>
    </Grid>
</Window>
